package zzz.icexxx.swing_demo;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Date;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.swing.ScreenUtil;
import cn.hutool.core.util.StrUtil;

public class ScreenImageUtil {

    public static void captureScreen(String path) {
        int width = ScreenUtil.getWidth();
        int height = ScreenUtil.getHeight();
        Rectangle screenRect = new Rectangle(10, 10, width, height);
        String date = DateUtil.format(new Date(), "yyyyMMdd_HHmmss");
        String newPath = path;
        newPath = StrUtil.addSuffixIfNot(newPath, "/");
        File outFile = new File(path + date + ".png");
        BufferedImage captureScreen = ScreenUtil.captureScreen(screenRect);
        ImgUtil.gray(captureScreen, outFile);
    }
}
